package com.coffee.takeoutserver.service.impl;

import com.coffee.takeoutserver.bean.Order;
import com.coffee.takeoutserver.bean.OrderExample;
import com.coffee.takeoutserver.dao.OrderMapper;
import com.coffee.takeoutserver.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> getOrdersByUserId(int userId) {
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andUseridEqualTo(userId);
        orderExample.setOrderByClause("id desc");
        return orderMapper.selectByExample(orderExample);
    }

    @Override
    public List<Order> getOrdersBySellerId(int sellerId) {
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andSelleridEqualTo(sellerId);
        orderExample.setOrderByClause("id desc");
        return orderMapper.selectByExample(orderExample);
    }

    @Override
    public void pay(Order order) {
        orderMapper.insert(order);
    }

    @Override
    public void insertComment(int orderId, String comment) {
        Order order = new Order();
        order.setId(orderId);
        order.setComment(comment);
        orderMapper.updateByPrimaryKeySelective(order);
    }
}
